package com.ruoyi.process.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.process.domain.ArgoProcess;
import com.ruoyi.process.service.IArgoProcessService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 农事过程任务Controller
 * 
 * @author qhr
 * @date 2024-02-27
 */
@RestController
@RequestMapping("/process/task")
public class ArgoProcessController extends BaseController
{
    @Autowired
    private IArgoProcessService argoProcessService;

    /**
     * 查询农事过程任务列表
     */
    @PreAuthorize("@ss.hasPermi('process:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArgoProcess argoProcess)
    {
        startPage();
        List<ArgoProcess> list = argoProcessService.selectArgoProcessList(argoProcess);
        return getDataTable(list);
    }

    /**
     * 导出农事过程任务列表
     */
    @PreAuthorize("@ss.hasPermi('process:task:export')")
    @Log(title = "农事过程任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArgoProcess argoProcess)
    {
        List<ArgoProcess> list = argoProcessService.selectArgoProcessList(argoProcess);
        ExcelUtil<ArgoProcess> util = new ExcelUtil<ArgoProcess>(ArgoProcess.class);
        util.exportExcel(response, list, "农事过程任务数据");
    }

    /**
     * 获取农事过程任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('process:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(argoProcessService.selectArgoProcessById(id));
    }

    /**
     * 新增农事过程任务
     */
    @PreAuthorize("@ss.hasPermi('process:task:add')")
    @Log(title = "农事过程任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArgoProcess argoProcess)
    {
        return toAjax(argoProcessService.insertArgoProcess(argoProcess));
    }

    /**
     * 修改农事过程任务
     */
    @PreAuthorize("@ss.hasPermi('process:task:edit')")
    @Log(title = "农事过程任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArgoProcess argoProcess)
    {
        return toAjax(argoProcessService.updateArgoProcess(argoProcess));
    }

    /**
     * 删除农事过程任务
     */
    @PreAuthorize("@ss.hasPermi('process:task:remove')")
    @Log(title = "农事过程任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(argoProcessService.deleteArgoProcessByIds(ids));
    }
}
